#include "PrecompiledHeaders.h"
#include "StringTokenizer.h"

StringTokenizer::StringTokenizer(std::string st, std::string se)
{
    str = st;
    sep = se;
    tok_start = tok_end = 0;
    doNext();
}

void StringTokenizer::doNext()
{
	is_next = (tok_end != std::string::npos);
	if (is_next) {
        tok_end = str.find_first_of(sep, tok_start);
        if (tok_end > tok_start)
            next_tok = str.substr(tok_start, tok_end-tok_start);
        tok_start = str.find_first_not_of(sep, tok_end+1);
    }
}
    
bool StringTokenizer::hasMoreTokens()
{
    return is_next;
}

std::string StringTokenizer::getNext()
{
    if (!is_next) throw std::string("No more tokens");
    std::string ret = next_tok;
    
    doNext();
    
    return ret;
}
